package com.lhoverc.mapper;

import com.lhoverc.pojo.entity.ActivityParticipationEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author: LiCheng
 * @CreateTime: 2025-04-22
 * @Description:
 * @Version: 1.0
 */
@Mapper
public interface ActivityParticipationMapper {

    /**
     * 添加数据
     * @param activityParticipationEntity
     */
    @Insert("insert into activity_participation (user_id, activity_id, username, activity_name, register_time)" +
            " VALUES (#{userId}, #{activityId}, #{username}, #{activityName}, #{registerTime})")
    void insert(ActivityParticipationEntity activityParticipationEntity);

    /**
     * 通过user和activity的id查询是否存在
     * @param userId
     * @param activityId
     * @return
     */
    @Select("select * from activity_participation where user_id = #{userId} and activity_id = #{activityId}")
    ActivityParticipationEntity getByUserIdAndActivityId(Integer userId, Integer activityId);

    /**
     * 将isDelete改为0（取消报名后再报名）
     * @param userId
     * @param activityId
     */
    @Update("update activity_participation set is_delete = 0, register_time = #{registerTime} where user_id = #{userId} and activity_id = #{activityId}")
    void updateIsDeleteTo0(Integer userId, Integer activityId, LocalDateTime registerTime);

    /**
     * 根据用户id查询报名的id
     * @param userId
     * @return
     */
    @Select("select activity_id from activity_participation where user_id = #{userId} and is_delete = 0")
    List<Integer> getIdByUserId(Integer userId);

    /**
     * 将isDelete改为1（取消报名）
     * @param userId
     * @param activityId
     */
    @Update("update activity_participation set is_delete = 1 where user_id = #{userId} and activity_id = #{activityId}")
    void updateIsDeleteTo1(Integer userId, Integer activityId);
}
